package mtn.lgdx.GPS;
import android.app.*;
import android.content.*;
import android.net.*;
import android.location.*;

public class Utils  { 
	public static int THEME_FLAG = 0;

	/** 
	 * Set the theme of the Activity, and restart it by creating a new Activity 
	 * of the same type. 
	 */
	public static void changeTheme(Activity activity) 
	{ 
		activity.finish();
		if (THEME_FLAG == 1) {
			THEME_FLAG = 0;
		}
		else {
			THEME_FLAG = 1;
		}
		activity.startActivity(new Intent(activity, activity.getClass()));
	} 
	
	public static int getTheme() {
		int _theme = -1;
		switch (THEME_FLAG) {
			case 1:
				_theme = R.style.AntiTheme;
				break;
			case 0:
				_theme = R.style.AppTheme;
		}
		return _theme;
	}
	
	public static int getMenuTitle1() {
		int _title = -1;
		switch (THEME_FLAG) {
			case 1:
				_title = R.string.toDay;
				break;
			case 0:
				_title = R.string.toNight;
		}
		return _title;
	}
	
	/**
	 * 对网络连接或GPS状态进行判断 
	 * @return true, 可用； false， 不可用
	 */
	public static boolean isOnline(Context context) {
		return isNetworkEnable(context) || isGpsEnable(context);
	}

	private static boolean isNetworkEnable(Context context) {
		ConnectivityManager connManager = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
		if (connManager.getActiveNetworkInfo() != null) {
			return connManager.getActiveNetworkInfo().isAvailable();
		}
		return false;
	}

	private static boolean isGpsEnable(Context context) {
		LocationManager locationManager = ((LocationManager)context.getSystemService(Context.LOCATION_SERVICE));
		return locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
	}
}
